<!-- 简单生产领料单 -->
<template>
    <div class="content">
      <div class="content-head">
        <div class="head-left">
          <el-form :inline="true" :model="formData" label-position="left" size="mini">
            <el-form-item label="单据编号" label-width="70px" class="form-item">
              <el-input v-model="formData.orderNumber" clearable placeholder="请输入单据编号"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" size="mini" icon="el-icon-refresh-left" @click="resetEvent">重置</el-button>
              <el-button type="success" size="mini" icon="el-icon-search" @click="searchEvent">查询</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div class="head-right">
          <el-radio-group v-model="formData.showType" size="small" @input="radioGroupChange">
            <el-radio-button label="按物料"></el-radio-button>
            <el-radio-button label="按单"></el-radio-button>
          </el-radio-group>
        </div>
      </div>
      <div class="content-table">
        <el-table :data="tableData" v-loading="tableLoading" style="width: 100%;" :max-height="tableMaxHeight" class="content-table-item">
          <el-table-column type="index" width="55" label="序号"></el-table-column>
          <el-table-column prop="orderNumber" label="单据编号" align="center" width="140"></el-table-column>
          <el-table-column prop="createTime" label="日期" align="center" width="150"></el-table-column>
          <el-table-column prop="" label="单据状态" align="center" width="">
            <template slot-scope="{row, $index}">
              <span>{{ row.approvalStatusName.includes('已审批') ? '完成' : '生效' }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="remark" label="生产车间" align="center" width="90"></el-table-column>
          <template v-if="this.formData.showType === '按物料'">
            <el-table-column prop="materialFields.code" label="物料编码" align="center" width=""></el-table-column>
            <el-table-column prop="materialFields.name" label="物料名称" align="center" width=""></el-table-column>
            <el-table-column prop="materialFields.standard" label="规格型号" align="center" width=""></el-table-column>
            <el-table-column prop="materialFields.comp" label="单位" align="center" width=""></el-table-column>
          </template>
          <el-table-column prop="planAmount" label="申请数量" align="center" width=""></el-table-column>
          <el-table-column prop="actualAmount" label="实发数量" align="center" width=""></el-table-column>
          <el-table-column prop="warehouseName" label="仓库" align="center" width=""></el-table-column>
          <el-table-column fixed="right" label="操作" align="center" width="80">
            <template slot-scope="scope">
              <el-button @click="detail(scope.row)" type="text" size="small">详情</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="content-footer">
        <el-pagination @size-change="handleSizeChange"  @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[10,20,40,80,100,200]" :page-size="pageSize" background layout="prev, pager, next,total, sizes, jumper" :total="total"></el-pagination>
      </div>
    </div>
  </template>
  
  <script>
  import { portrait, autoOrientation, fullscreen } from "@/utils/rotatingScreen.js";
  import { reqProductMaterialRequestList } from "@/api/ProductionMaterialRequest.js";
  import TableHeadFilter from "@/components/tableHeadFilter/index.vue";
  import { sleep } from "@/utils/toosls.js";
  export default {
    name:"productionMaterialRequest",  //简单生产领料单
    components:{
      TableHeadFilter
    },
    data() {
      return {
        formData:{
          orderNumber:"",
          showType:"按物料"
        },
        tableData:[],
        currentPage:1,
        pageSize:10,
        total:0,
        tableLoading:false,
        tableMaxHeight:450,
        showTypeList:[
          {title:"按物料",type:"material"},
          {title:"按单",type:"order"}
        ]
      }
    },
    mounted(){
      this.getProductionMaterialRequestList();
      this.calculateTableMaxHeight();
      window.addEventListener("resize",this.calculateTableMaxHeight);
      document.title = "简单生产领料单";
      const isDevelopment = process.env.NODE_ENV === 'development';
      if(!isDevelopment){
        autoOrientation();
      }
    },
    beforeDestroy(){
      window.removeEventListener("resize",this.calculateTableMaxHeight);
    },
    methods:{
      //分页器
      handleCurrentChange(curPage){
        this.currentPage = curPage;
        this.getProductionMaterialRequestList();
      },
      handleSizeChange(pageSize){
        this.pageSize = pageSize;
        this.getProductionMaterialRequestList();

      },
      calculateTableMaxHeight(){
        const dom = document.querySelector(".content-table");
        this.$nextTick(() => {
          this.tableMaxHeight = dom.offsetHeight - 10;
        })
      },
      detail(row){
        this.$router.push({name: "ProMaterialReqDetail",params:{row:row,type:'detail'}});
      },
      edit(row){
        this.$router.push({name: "ProMaterialReqDetail",params:{row:row,type:'edit'}});
      },
      resetEvent(){
        this.formData.orderNumber = "";
        this.formData.showType = "按物料";
        this.getProductionMaterialRequestList();
      },
      searchEvent(){
        const searchStr = this.formData.orderNumber;
        if(searchStr.trim().length === 0){
          this.$notify.error({title: '提示',message:'请输入单据编号后进行查询'});
          return;
        }
       this.getProductionMaterialRequestList();
      },
      getProductionMaterialRequestList(){
        const { orderNumber,showType } = this.formData;
        const typeInfo = this.showTypeList.find(l => l.title === showType);
        const parameter = { current:this.currentPage, size:this.pageSize, orderNumber, showType:typeInfo.type };
        this.tableLoading = true;
        reqProductMaterialRequestList(parameter).then(res => {
          if(res.data.code === 200){
            this.tableData = res.data.data.content;
            this.total = res.data.data.totalElements;
          }
          console.log('分页请求简单生产领料单列表信息',res);
          this.tableLoading = false;
        },error => {
          this.$message({type:"error",message:"简单生产领料单列表信息请求失败"});
          this.tableLoading = false;
          console.log('分页请求简单生产领料单列表信息',error);
        })
      },
      async radioGroupChange(){
        this.tableLoading = true;
        await sleep(5000);
        this.getProductionMaterialRequestList();
      }
    }
  }
  </script>
  
<style lang='scss' scoped>
.content{
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 1%;
  box-sizing: border-box;
  user-select:auto;

  .content-head{
    flex: 0.5;
    display: flex;
    justify-content: space-between;
    .form-item{
      margin-right: 2vw;
    }
  }
  .content-table{
    flex: 9;
    margin: 10px 0;
    .table-date{
      width: 100%;
      height: 2%;
      min-height: 15px;
      margin-bottom: 0.5%;
      display: flex;
      justify-content: right;
    }
    .table-main{
      width: 100%;
      height: 98%;
    }
  }
  .content-footer{
    flex: 0.5;
    display: flex;
    justify-content: flex-end;
  }
}
::v-deep .el-table__header th {
  padding: 0; /* 调整上下内边距 */
}
::v-deep .el-table__row {
  margin-bottom: 15px; /* 调整这个值来改变行间距 */
  height: 60px;
}
::v-deep .el-table .el-table__cell{
  padding: 0;
}
</style>